using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace masterCard
{
    public partial class frmBridgeMasterCard : Form
    {
        private BridgeGameEngine m_cGameEngine;
        private BridgeDisplay m_cDisPlay;
        public frmBridgeMasterCard()
        {
            InitializeComponent();
        }

        private void frmMasterCard_Load(object sender, EventArgs e)
        {
            m_cGameEngine = masterCard.BridgeGameEngine.getBridgeGameEngine();
            m_cDisPlay = new BridgeDisplay(this);

            this.MaximizeBox = false;
            this.AutoSize = false;

            btnPlay.Top = this.Height / 2;
            btnPlay.Left = this.Width / 2;
            DrawState(m_cGameEngine.State);
        }

        private void btnPlay_Click(object sender, EventArgs e)
        {
            object tag = ((System.Windows.Forms.Button)sender).Tag;

            switch (m_cGameEngine.State)
            {
                case GameState.Deal:
                   
                    m_cGameEngine.StartNewGame();
                    m_cGameEngine.ShufflePack();
                    m_cGameEngine.DistributeCard();
                    BridgePlayer player;
                    for (Position pos = Position.North; pos <= Position.West; pos++)
                    {
                        player = m_cGameEngine.GetPlayer(pos);
                        player.ArrangeCard();
                        m_cDisPlay.Draw(player);
                    }
                    m_cGameEngine.UpdateState();
                    DrawState(m_cGameEngine.State);
                    break;
                case GameState.Auction:
                   
                    frmBridgeBid frmBid = new frmBridgeBid();
                    frmBid.ShowDialog();
                    m_cGameEngine.StartBidding();
                    break;
                case GameState.Play:
                    m_cGameEngine.StartPlay();
                    break;
                case GameState.Score:
                    m_cGameEngine.ShowPoint();
                    break;
            }
        }

        private void DrawState(GameState gameState)
        {
            btnPlay.Text = m_cGameEngine.State.ToString();
        }
    }
}